/*
 * Created on Oct 18, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package net.jxta.myjxta.plugins.vojxta;

import org.xiph.speex.SpeexDecoder;

import java.io.StreamCorruptedException;

/**
 * @author Ravi
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public final class Decoder{

    private final SpeexDecoder decoder;
    
	public static void main(String[] args) {
	}

	/**
	 * 
	 */
	public Decoder() {
        
		super();
        
		decoder = new SpeexDecoder();
        
		decoder.init(AudioResource.MODE, AudioResource.SAMPLE_RATE, AudioResource.CHANNELS, false);	// boolean enhanced = false
	}
	
	/**
	 * 
	 * @param buf
	 * @return speex decoded byte array
	 */
	public byte[] decode(byte[] buf){
        
		try {
            
			decoder.processData(buf, 0, buf.length);
            
		} catch (StreamCorruptedException e) {
            
			e.printStackTrace();
            
		}
		byte[] decoded = new byte[decoder.getProcessedDataByteSize()];
        
		decoder.getProcessedData(decoded, 0);
		
		return decoded;
	}
	
	
}
